Function LoadKeywords:String(url:String)
	Local cmdfile:TStream = ReadFile(url)
	Local Keys:String = ""
	While Not Eof(cmdfile)
		Local L:String = ReadLine(cmdfile).Trim()
		If L.StartsWith("//") Then
			Continue
		End If
		Keys:+L + " "
	Wend
	
	Return Keys
End Function

Type TScintillaConfig
	Field scintilla:TScintillaTextArea
	Field lexer:Int
	Field styles:TMap = CreateMap()
	Field Keywords:String[] = New String[10]
	
	Function Create:TScintillaConfig(area:TScintillaTextArea,lexer:Int = -1)
		Local SC:TScintillaConfig = New TScintillaConfig
		SC.scintilla = area
		SC.Setlexer(lexer)
		Return SC
	End Function
	
	Method Setkeywords(slot:Int = 0, Keys:String = "")
		Assert slot >= 0 Or slot <= 9, "Keyword slot out of range (0 - 9)"
		Keywords[slot] = Keys
		Update()
	End Method
	
	Method Setlexer(_lexer:Int)
		lexer = _lexer
		Update()
	End Method
	
	Method SetStyle(id:Int, font:TGuiFont = Null, forecolor:Int[] = Null, backcolor:Int[] = Null)
		If styles.contains(String(id)) Then
				styles.Remove(String(id))
		End If
		Local _style:ScintillaStyle = ScintillaStyle.Create(id, font, forecolor, backcolor)
		styles.Insert(String(id), _style)
		_style._Register(scintilla)
		Update()
	End Method
	
	Method SetCaret(forecolor:Int[], Style:Int = CARETSTYLE_LINE)
		scintilla.Setcaretfore(forecolor[0], forecolor[1], forecolor[2])
		scintilla.Setcaretstyle(Style)
	End Method
	
	Method setProperty(key:String, value:String)
		scintilla.setProperty(key, value)
	End Method
	
	Method Setindentationguides(Style:Int = SC_IV_NONE)
		scintilla.Setindentationguides(Style)
	End Method

	
	Method Update()
		If scintilla <> Null Then
			scintilla.Setlexer(lexer)
			
			For Local s:ScintillaStyle = EachIn styles.Values()
				s.Apply()
			Next
			
			For Local slot:Int = 0 To 9
				scintilla.Setkeywords(slot, Keywords[slot])
			Next
		End If
	End Method
	
End Type

Type ScintillaStyle
	Field id:Int = 0
	Field scintilla:TScintillaTextArea
	Field font:TGuiFont = Null
	Field forecolor:Int[] = [0, 0, 0]
	Field backcolor:Int[] = [255, 255, 255]
		
	Function Create:ScintillaStyle(styleid:Int = 0, font:TGuiFont = Null, forecolor:Int[] = Null, backcolor:Int[] = Null)
		Local Style:ScintillaStyle = New ScintillaStyle
		Style.id = styleid
		If font <> Null Then Style.font = font
		If forecolor <> Null Then Style.forecolor = forecolor
		If backcolor <> Null Then Style.backcolor = backcolor
		Return Style
	End Function
	
	Method Apply()
		If scintilla <> Null Then
			scintilla.Stylesetback(id, backcolor[0], backcolor[1], backcolor[2])
			scintilla.Stylesetfore(id, forecolor[0], forecolor[1], forecolor[2])
			If font <> Null Then
				scintilla.StyleSetFont(id, font.name)
				scintilla.Stylesetsize(id, Int(font.size))
				scintilla.Stylesetbold(id, (font.Style & FONT_BOLD) > 0)
				scintilla.Stylesetitalic(id, (font.Style & FONT_ITALIC) > 0)
				scintilla.Stylesetunderline(id, (font.Style & FONT_UNDERLINE) > 0)
			End If
		End If
	End Method
	
	Method _Register(s:TScintillaTextArea)
		scintilla = s
		Apply()
	End Method
	
End Type